package pkg;

import javax.servlet.http.*;

import java.util.*;

import org.apache.struts.action.*;
import org.hibernate.Query;
import org.hibernate.Session;
import HibernateBeans.Customer_Products;


public class ProductSelectionAction extends Action {
	public static List<Customer_Products> onecplist;
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		HttpSession session2 = request.getSession();

		
		
		Session session=CustomerDetailsAction.session;
		String hql = "from HibernateBeans.ProductDetails where pid=:pid";
		Query query = session.createQuery(hql);
		query.setString("pid", ((Plans)form).getProduct_internet());
		List<HibernateBeans.ProductDetails> results = query.list();
		query.setString("pid", ((Plans)form).getProduct_tv());
		results.addAll(query.list());
		int i = 0;
		for(HibernateBeans.ProductDetails p : results){
			Customer_Products cp = new Customer_Products();
			cp.setCp_id(99);
			cp.setProdd(p);
			cp.setCustd((HibernateBeans.CustomerDetails) session.get(HibernateBeans.CustomerDetails.class, CustomerDetailsAction.id));
			session.save(cp);
			System.out.println("customer_products saved");
		}
		

		return mapping.findForward("Verification");

	}
}